Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvstreamer: fix a bug with incorrect processing of empty scan responses #75888

Merged
merged 2 commits into from
Feb 9, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Feb 2, 2022

kvstreamer: fix a bug with incorrect processing of empty scan responses

Previously, the Streamer could get stuck indefinitely when a response
for a Scan request came back empty - namely the response neither had no
bytes inside nor ResumeSpan set (this is the case when there is no data
in the key span to scan). This would lead to GetResults call being
stuck thinking there are more responses to come back, and none would
show up.

This is now fixed by creating a Result with an empty Scan response
inside of it. This approach makes it easier to support Scans that span
multiple ranges and the last range has no data in it - we want to be
able to set Complete field on such an empty Result.

Since this was the only known bug with the Streamer implementation,
the streamer is now used by default again.

Fixes: #75708.

Release note: None

kvstreamer: minor cleanup

This commit replaces the last buffered channel we had in the Streamer
code in favor of a condition variable which simplifies the control flow
a bit.

Additionally, this commit refactors the code so that empty Get responses
are not returned which allows us to clean up TxnKVStreamer a bit. Care
has to be taken so that we still signal the client's goroutine waiting
for results when an empty Get response comes back (similar to the bug
fixed by the previous commit).

Also, the tracking of the "number of outstanding requests" in
TxnKVStreamer has been removed since it provided little value (and
probably was broken anyway).

Release note: None

@yuzefovich yuzefovich added the do-not-merge bors won't merge a PR with this label. label Feb 2, 2022
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the streamer-debug branch 13 times, most recently from 79fe38f to ed94654 Compare February 4, 2022 01:07
@yuzefovich yuzefovich changed the title kvstreamer: WIP on fixing the streamer kvstreamer: fix a bug with incorrectly processing empty scan responses Feb 4, 2022
@yuzefovich yuzefovich changed the title kvstreamer: fix a bug with incorrectly processing empty scan responses kvstreamer: fix a bug with incorrect processing of empty scan responses Feb 4, 2022
@yuzefovich yuzefovich force-pushed the streamer-debug branch 3 times, most recently from 1e5f570 to 56a56ac Compare February 5, 2022 04:37
@yuzefovich yuzefovich marked this pull request as ready for review February 5, 2022 04:39
@yuzefovich yuzefovich requested a review from a team as a code owner February 5, 2022 04:39
@yuzefovich yuzefovich removed the do-not-merge bors won't merge a PR with this label. label Feb 5, 2022
@yuzefovich yuzefovich requested review from rytaft, rharding6373 and a team February 5, 2022 04:39
Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix. I have some initial comments, but still need to review most of the second commit.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rytaft and @yuzefovich)


pkg/sql/row/kv_batch_streamer.go, line 41 at r1 (raw file):

		"Enabling this will increase the speed of lookup/index joins "+
		"while adhering to memory limits.",
	true,

Did you mean to turn this on by default in this bug fix? If so, this should be called out in the commit message at least.

Also, when it is enabled by default, it would be good to keep some test coverage where it is disabled to make sure the other code path is still operational -- unless you think that the operations that don't support the streamer yet provide sufficient coverage.


pkg/kv/kvclient/kvstreamer/streamer_test.go, line 461 at r1 (raw file):

		var union roachpb.RequestUnion_Scan
		makeKey := func(pk int) []byte {
			return []byte{190, 137, byte(136 + pk)}

Out of curiosity...what are these magic numbers?

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rharding6373 and @rytaft)


pkg/sql/row/kv_batch_streamer.go, line 41 at r1 (raw file):

Previously, rharding6373 (Rachael Harding) wrote…

Did you mean to turn this on by default in this bug fix? If so, this should be called out in the commit message at least.

Also, when it is enabled by default, it would be good to keep some test coverage where it is disabled to make sure the other code path is still operational -- unless you think that the operations that don't support the streamer yet provide sufficient coverage.

Yes, I did mean to turn it on by default since the first commit fixes the only known issue. Updated the commit message to include this note.

I'm not really concerned about the test coverage of the "streamer off" case because that code path is essentially everything that goes through the SQL layer and touches KV whereas the streamer code path is specific to only index joins in some cases.


pkg/kv/kvclient/kvstreamer/streamer_test.go, line 461 at r1 (raw file):

Previously, rharding6373 (Rachael Harding) wrote…

Out of curiosity...what are these magic numbers?

These make up a /t/primary/pk key, added a comment.

@rharding6373 rharding6373 self-requested a review February 8, 2022 20:15
Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rharding6373 and @rytaft)

Previously, the `Streamer` could get stuck indefinitely when a response
for a Scan request came back empty - namely the response neither had no
bytes inside nor ResumeSpan set (this is the case when there is no data
in the key span to scan). This would lead to `GetResults` call being
stuck thinking there are more responses to come back, and none would
show up.

This is now fixed by creating a Result with an empty Scan response
inside of it. This approach makes it easier to support Scans that span
multiple ranges and the last range has no data in it - we want to be
able to set Complete field on such an empty Result.

Since this was the only known bug with the `Streamer` implementation,
the streamer is now used by default again.

Release note: None
This commit replaces the last buffered channel we had in the `Streamer`
code in favor of a condition variable which simplifies the control flow
a bit.

Additionally, this commit refactors the code so that empty Get responses
are not returned which allows us to clean up `TxnKVStreamer` a bit. Care
has to be taken so that we still signal the client's goroutine waiting
for results when an empty Get response comes back (similar to the bug
fixed by the previous commit).

Also, the tracking of the "number of outstanding requests" in
`TxnKVStreamer` has been removed since it provided little value (and
probably was broken anyway).

Release note: None
@yuzefovich
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 9, 2022

Build succeeded:

@craig craig bot merged commit 456ff4c into cockroachdb:master Feb 9, 2022
@yuzefovich yuzefovich deleted the streamer-debug branch February 9, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql/logictest: logic tests occasionally are timing out because of the streamer
3 participants